
package cn.butcher.utils;

import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
//导入可选配置类
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
// 导入对应SMS模块的client
import com.tencentcloudapi.sms.v20210111.SmsClient;
// 导入要请求接口对应的request response类
import com.tencentcloudapi.sms.v20210111.models.SendSmsRequest;
import com.tencentcloudapi.sms.v20210111.models.SendSmsResponse;

//测试一下
//整理一下，封装工具类
public class SendMsg {

    public static void send(String templateId, String[] phoneNumberSet, String[] templateParamSet) throws TencentCloudSDKException {
        Credential cred = new Credential("AKIDzoMddMoztWsxlHXWEfqkNkrhGXXHkwqU", "OVLuCCvMXUBbkcDXMvCCvOaV9XeT1JK4");
        HttpProfile httpProfile = new HttpProfile();
        httpProfile.setReqMethod("POST");
        httpProfile.setConnTimeout(60);
        httpProfile.setEndpoint("sms.tencentcloudapi.com");
        ClientProfile clientProfile = new ClientProfile();
        clientProfile.setSignMethod("HmacSHA256");
        clientProfile.setHttpProfile(httpProfile);
        SmsClient client = new SmsClient(cred, "ap-guangzhou", clientProfile);
        SendSmsRequest req = new SendSmsRequest();
        // 以上基本是不用动的

        // =============================================================================

        String sdkAppId = "1400547755";
        req.setSmsSdkAppId(sdkAppId);

        /* 短信签名内容: 使用 UTF-8 编码，必须填写已审核通过的签名，签名信息可登录 [短信控制台] 查看 */
        String signName = "TXButcher";
        req.setSignName(signName);
        /* 国际/港澳台短信 SenderId: 国内短信填空，默认未开通，如需开通请联系 [sms helper] */
        String senderid = "";
        req.setSenderId(senderid);
        String sessionContext = "xxx";
        req.setSessionContext(sessionContext);
        /* 短信号码扩展号: 默认未开通，如需开通请联系 [sms helper] */
        String extendCode = "";
        req.setExtendCode(extendCode);

        // =============================================================================

        //String templateId = "1046801"; // 这是需要变动的
        req.setTemplateId(templateId);

        //String[] phoneNumberSet = {"+8619986048089", "+8617777334316", "+8615289609656"}; // 这是需要变动的
        req.setPhoneNumberSet(phoneNumberSet);

        //String[] templateParamSet = {"xxx","iii"}; // 这是需要变动的 ，这就是我们占位符要填充的内容
        req.setTemplateParamSet(templateParamSet);

        SendSmsResponse res = client.SendSms(req);
        // 输出json格式的字符串回包
        System.out.println(SendSmsResponse.toJsonString(res));
        // 也可以取出单个值，你可以通过官网接口文档或跳转到response对象的定义处查看返回字段的定义
        System.out.println(res.getRequestId());
    }

    public static void main(String[] args) throws TencentCloudSDKException {
        // 测试一下
        String[] phoneNumberSet = {"+8615289609656"};
        String[] templateParamSet = {"梁双祥", "07-28至07-30"};
        send("1046801", phoneNumberSet, templateParamSet);

    }
}